#define _CRT_SECURE_NO_WARNINGS 1
#include<Stdio.h>

int GetMidi(int* a, int begin,int end)
{
	int midi = (begin + end) / 2;
	if (a[begin] > a[midi])
	{
		if (a[midi] > a[end])
		{
			return midi;
		}
		else
		{
			if (a[begin] > a[end])
			{
				return end;
			}
			else
			{
				return begin;
			}
		}
	}
	else // a[begin] <= a[midi]
	{
		if(a[begin] > a[end])
		{
			return begin;
		}
		else
		{
			if (a[midi] > a[end])
			{
				return end;
			}
			else
			{
				return midi;
			}
		}
	}
}

int main()
{
	int a[] = { 1,2,3,4,5,6,7,8,9,10 };
	int size = sizeof(a) / sizeof(a[0]);

	int ret = GetMidi(a, 0, size - 1);
	printf("%d\n", ret);
	return 0;
}